home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / aie9003.zip / TRACEHLP.ARI < prev    next >
Text File  |  1989-12-10  |  6KB  |  204 lines

  1. :- module tracehlp.  % what newtrace needs
  2.  
  3.  
  4. :- public
  5.      hide_cursor / 0 : far,           /* In module: ARITY5.ARI              */
  6.      restore_cursor / 0 : far,        /* In module: ARITY5.ARI              */
  7.      getglobal / 2 : far,             /* In module: LIBRARY.ARI             */
  8.      non_empty / 1 : far,             /* In module: LIBRARY.ARI             */
  9.      addout / 2 : far,                /* In module: filemod.ARI             */
  10.      rem_global_value / 1 : far,      /* In module: LIBRARY.ARI             */
  11.      setglobal / 2 : far.             /* In module: LIBRARY.ARI             */
  12.  
  13. :- public  non_empty / 1 : far.
  14.  
  15.  
  16. restore_cursor :- !.
  17. hide_cursor :- !.
  18.  
  19. /*************************************************************************/
  20. /***************** Source Code for Global Variable Predicates ************/
  21. /*************************************************************************/
  22.  
  23.  
  24.  
  25. %%%%%%%%%%%%%%%% setglobal : set value of global variable %%%%%%%%%%
  26.  
  27. setglobal( Var, Val ) :-
  28.        recorded( Var, zzz_global_value(  _  ), Ref),
  29.        !,
  30.        (    replace( Ref,
  31.                      zzz_global_value(  Val )
  32.                    ),
  33.             !
  34.           ;
  35.             remglobal( Var),
  36.             setglobal( Var, Val)
  37.        ).
  38.  
  39. setglobal( Var, Val ) :-
  40.        recorda( Var, zzz_global_value( Val ) , _).
  41.  
  42.  
  43. %%%%%%%%%%%%%%%% getglobal : get value of global variable %%%%%%%%%%
  44.  
  45. getglobal( Var, Val) :-
  46.        recorded( Var, zzz_global_value( Val ) , _).
  47.  
  48. %%%%%%%%%%%%%%%% has_global_value : true if variable has global value %%%%%
  49.  
  50. has_global_value( Var)  :-
  51.        recorded( Var, zzz_global_value(  _  ) , _).
  52.  
  53. %%%%%%%%%%%%%%%% rem_global_value : remove global value %%%%%%%%%%%%%%%%%%%
  54.  
  55. remglobal( Var ) :-
  56.        recorded( Var, zzz_global_value(  _  ), Ref),
  57.        !,
  58.        hard_erase( Ref).
  59. remglobal( _).
  60.  
  61. rem_global_value( Var ) :-
  62.      remglobal( Var ) .
  63.  
  64.  
  65. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  66. %%%%%%%%%%%% addout : add output to the end of a file %%%%%%%%%%%%%%%%%%%%%%%
  67. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  68. /*
  69. PURPOSE : add output to the end of a file.
  70.  
  71. CALL:  addout( File , Term )
  72.  
  73. INPUT ARGS:
  74.  
  75.      File = file to write the output from Term to.  This output is put
  76.             at the end of the file.  If the file does not exist, one
  77.             is created.
  78.  
  79.      Term = a term which is executed.  Output from write, nl, etc.
  80.             go to File instead of to the screen.
  81.  
  82. SUCCESS CONDITIONS:
  83.  
  84.      Succeeds when Term succeeds, fails when Term fails.
  85.  
  86. WHEN TO USE THIS:
  87.  
  88.      If you want to write some output to a file, you can write
  89.      a goal to do it just like you would to the screen.  If
  90.      GOAL is the goal that produces the output and FILE is the
  91.      file you want to write it to, call
  92.  
  93.           addout( FILE , GOAL )
  94.  
  95.      Each time 'addout' is called, it writes the output to the
  96.      end of FILE, and then CLOSES the file.  This guarantees that
  97.      even if the program crashes, the output already produced
  98.      is safe in the file.
  99.  
  100. */
  101.  
  102. :- mode addout( + , + ).
  103.  
  104. addout( File , Term ) :-
  105.      open_for_appending( Handle, File),
  106.      tell_h( Handle ),
  107.      (
  108.              call(  Term ),
  109.              !,
  110.              told,
  111.              close( Handle )
  112.          ;
  113.              !,
  114.              told,
  115.              close( Handle ),
  116.              fail
  117.      ).
  118.  
  119.  
  120.  
  121. /*
  122. #########################################################################
  123.                  open_for_appending
  124. #########################################################################
  125.  
  126. Call:
  127.  
  128.     open_for_appending(Outhandle, Filename)
  129.  
  130. Input args:
  131.  
  132.     Filename = name of file to be opened for appending
  133.  
  134. Output args :
  135.  
  136.     Outhandle = handle for file of name Filename open for appending
  137.  
  138. Effect:  Opens file of name Filename for appending.  Opens existing
  139.          file if there is one.  Creates new file if necessary.
  140.  
  141. Success conditions:
  142.  
  143.          Succeeds whenever Filename can be opened for appending.
  144.  
  145. */
  146. open_for_appending(Outhandle, Filename) :-
  147.         file_exists(Filename),!,
  148.         open(Outhandle,  Filename  , a).
  149.  
  150. open_for_appending(Outhandle, Output_file ) :-
  151.      create_new_file_for_appending(Outhandle,Output_file).
  152.  
  153.  
  154.  
  155. /*
  156. #########################################################################
  157.                  File Exits
  158. #########################################################################
  159.  
  160.    */
  161.  
  162. file_exists(Filename):-
  163.     directory(Filename,_,_,_,_,_).  /* look for Filename on disk */
  164.                                     /* succeed if there */
  165.  
  166.  
  167. /*
  168. #########################################################################
  169.                  create_new_file_for_appending
  170. #########################################################################
  171.  
  172.             create_new_file_for_appending(Outhandle,Output_file)
  173.  
  174.    Opens an output file for appending stuff into the file.
  175.  
  176. Arument               Mode        Function
  177. -------               ----        --------
  178. Outhandle             out         output file handle, file open for append
  179. Output_file           in          name of file to be opened for append
  180.  
  181. */
  182.  
  183. create_new_file_for_appending(Outhandle,Output_file):-
  184.           create(H1,Output_file),
  185.           close(H1),
  186.          open(Outhandle,Output_file,a).
  187.  
  188.  
  189.  
  190.  
  191. /*************************************************************************/
  192. /********* non_empty : true for non-empty sets ***************************/
  193. /*************************************************************************/
  194.  
  195.        % mode revised by rk 9-28-89
  196. :- mode non_empty(  +  ).
  197.  
  198. non_empty(  [_ | _ ]).
  199.  
  200.  
  201.  
  202.  
  203. %%%%%%%%%%%%%%%%%%%% eof %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  204.